package main

import (
	"encoding/json"
	"fmt"
	"reflect"
)

type person struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}

func test1() {
	var x int = 42
	// 获取类型
	t := reflect.TypeOf(x)
	// 获取值
	v := reflect.ValueOf(x)

	fmt.Println("类型: ", t)
	fmt.Println("值: ", v)
}

func test2() {
	p := person{Name: "Alice", Age: 30}
	data, _ := json.Marshal(p)
	fmt.Println(string(data)) // 输出：{"name":"Alice","age":30}

	var p2 person
	json.Unmarshal(data, &p2)
	fmt.Println(p2) // 输出：{Alice 30}
}

func main() {
	test2()
	test2()
}
